package com.nuc.impl1;

/**
 * Time    : 2023/3/28 19:25
 * Author  : 王摇摆
 * FileName: Role.java
 * Software: IntelliJ IDEA 2020.2.2
 * Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
 */

public class Role {
    private String name;
    private String weapon;

    public Role() {
    }

    public Role(String name, String weapon) {
        this.name = name;
        this.weapon = weapon;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getWeapon() {
        return weapon;
    }

    public void setWeapon(String weapon) {
        this.weapon = weapon;
    }

    public void attack(Monster monster) {
        //首先判断怪物是否已经死亡
        if (monster.getHealthPoint() <= 0) {
            System.out.println(monster.getName() + "已经死亡，无法继续攻击！");
            return;
        }

        //判断剑客使用什么武器来攻击怪物
        if (weapon == "WoodenSword") {
            monster.decreaseHealthPoint(20);
            if (monster.getHealthPoint() <= 0)
                System.out.println("木剑攻击成功！怪物" + monster.getName() + "已经死亡。");
            else
                System.out.println("木剑攻击成功！怪物" + monster.getName() + "减少20生命值，还剩" + monster.getHealthPoint() + "生命值。");
        } else if (weapon == "IronSword") {
            monster.decreaseHealthPoint(50);
            if (monster.getHealthPoint() <= 0)
                System.out.println("铁剑攻击成功！怪物" + monster.getName() + "已经死亡。");
            else
                System.out.println("铁剑攻击成功！怪物" + monster.getName() + "减少50生命值，还剩" + monster.getHealthPoint() + "生命值。");
        } else if (weapon == "MagicSword") {
            monster.decreaseHealthPoint(100);
            if (monster.getHealthPoint() <= 0)
                System.out.println("铁剑攻击成功！怪物" + monster.getName() + "已经死亡。");
            else
                System.out.println("铁剑攻击成功！怪物" + monster.getName() + "减少100生命值，还剩" + monster.getHealthPoint() + "生命值。");
        } else
            System.out.println("剑客没有武器，无法对怪物造成攻击！");
    }
}
